package com.hiv.utils;

import org.apache.pdfbox.multipdf.PDFMergerUtility;

import java.util.List;

/**
 * @author zhanghong
 */
public class PdfUtil {

    /**
     * 将多个pdf合并到一个pdf文件中
     *
     * @param pdfs
     * @param finalPdfPath
     * @throws Exception
     */
    public static void mergePDF(List<String> pdfs, String finalPdfPath) throws Exception {
        PDFMergerUtility mergePdf = new PDFMergerUtility();
        for (String file : pdfs) {
            if (file.toLowerCase().endsWith("pdf")) {
                mergePdf.addSource(file);
            }
        }
        mergePdf.setDestinationFileName(finalPdfPath);
        mergePdf.mergeDocuments();
        System.out.println("merge over");
    }
}
